home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / MACFILE.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  3KB  |  119 lines

  1. /*    SCCS Id: @(#)macfile.c    3.0    88/08/05
  2. /*      Copyright (c) Johnny Lee, 1989.         */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /*    Common routines to locate files using mac dialog boxes */
  6.  
  7. #include "config.h"
  8. #ifdef MACOS
  9.  
  10. #define    LARGE_SFGETDLG    -4000
  11. short
  12. findNamedFile(filename,type,reply)
  13. char    *filename;
  14. short    type;    /* if 0 - don't care if name matches selected file */
  15. SFReply    *reply;
  16. {
  17.     DialogPtr    dialog;
  18.     short    numTypes;
  19.     SFTypeList    types;    
  20.     Str255    prompt, name;
  21.     Point    where;
  22.     short    ok;
  23.     DialogRecord    storage;
  24.     
  25.     name[0] = (char)strlen(filename);
  26.     Strcpy((char *)&name[1], filename);
  27.     SetResLoad(TRUE);
  28.     
  29.     if (type == 1)
  30.         ParamText("\005 save","\004 for",name,"");
  31.     else
  32.         ParamText("","",name,"");
  33.     
  34.     where.h = 80;
  35.     where.v = 111;
  36.     ok = FALSE;
  37.     
  38.     switch (type) {
  39.       case 0:    /* don't care what file gets loaded */
  40.           numTypes = -1;
  41.           break;
  42.       case 1:    /* limit what types of files can be selected */
  43.           numTypes = 2;
  44.         types[0] = SAVE_TYPE;
  45.         types[1] = EXPLORE_TYPE;
  46.         break;
  47.       case 2:    /* unlimited types of files but names have to match*/
  48.           numTypes = -1;
  49.           break;
  50.     }
  51.     reply->good = TRUE;
  52.     do {
  53.         SFPGetFile(where,prompt,0L,numTypes,types,0L,reply,LARGE_SFGETDLG,0L);
  54.         if (reply->good) {
  55.             if ((type == 2 && 
  56.                 !strncmp((char *)&name[1],
  57.                     (char *)&(reply->fName[1]), (short)name[0]))
  58.                  || (type<2)) {
  59.                 SetVol(0L,reply->vRefNum);
  60.                 ok = TRUE;
  61.             }
  62.         }
  63.     } while (!ok && reply->good);
  64.  
  65.     return ok;
  66. }
  67.  
  68. #ifdef CUSTOM_IO
  69. extern WindowPtr HackWindow;
  70. extern short macflags;
  71. /*    this function also gets called by topten() in topten.c to
  72.  *    locate the record file, but it doesn't matter at this point
  73.  *    since the game is over by now. If nethack ever restarts,
  74.  *    this will have to change.
  75.  */
  76.  
  77. FILE *
  78. openFile(fileName, rdmode)
  79. char    *fileName, *rdmode;
  80. {
  81.     term_info *t;
  82.     FILE    *fp;
  83.         
  84.     t = (term_info *)GetWRefCon(HackWindow);
  85.  
  86.     SetVol(0L, t->recordVRefNum);
  87.     fp = fopen(fileName, rdmode);
  88.     if (!fp) {        
  89.         SFReply    reply;
  90.  
  91.         if (t->auxFileVRefNum) {
  92.             SetVol(0L,t->auxFileVRefNum);
  93.         }
  94.         
  95.         reply.good = false;
  96.         fp = fopen(fileName, rdmode);
  97.         if (!fp && findNamedFile(fileName,2,&reply)) {
  98.             if (reply.good) {
  99.                 t->auxFileVRefNum = reply.vRefNum;
  100.             }
  101.         }
  102.         
  103.         if (!fp)
  104.             fp = fopen(fileName, rdmode);
  105.         else if (!t->auxFileVRefNum && reply.good) {
  106.             (void)GetVol((StringPtr)&reply.fName,&t->auxFileVRefNum);
  107.         }
  108.  
  109.         SetPort(HackWindow);
  110.         if ((macflags & fDoUpdate) && !reply.good)
  111.             docrt();
  112.  
  113.     }
  114.  
  115.     return fp;
  116. }
  117. #endif
  118. #endif
  119.